<div class="houtai-item-list">
    <div class="address-show">
        <table>
            <tr>
                <th class="houtai-addr">地址信息</th>
            </tr>
            <tr>
                <td>订单号:</td>
                <td><span class="order-id">信息加载中...</span></td>
            </tr>
            <tr>
                <td>购买用户：</td>
                <td><span class="order-buyer">信息加载中...</span></td>
            </tr>
            <tr>
                <td>收货人:</td>
                <td><span class="order-user">信息加载中...</span></td>
            </tr>
            <tr>
                <td>手机:</td>
                <td><span class="order-phone">信息加载中...</span></td>
            </tr>
            <tr>
                <td>创建时间:</td>
                <td><span class="`order-created`">信息加载中...</span></td>
            </tr>
            <tr>
                <td>联系地址:</td>
                <td><span class="order-addr">信息加载中...</span></td>
            </tr>
        </table>
    </div>
    <table>
        <thead>
        <tr>
            <th>序号</th>
            <th>宝贝图片</th>
            <th>宝贝名字</th>
            <th>单价</th>
            <th>数量</th>
            <th>规格</th>
        </tr>
        </thead>
        <tbody class="houtai-order-list">
            <tr class="houtai-order-desc">
                <td>1</td>
                <td class="houtai-item-img">
                    <img src="img/default.jpg" />
                </td>
                <td>女娃娃，抱枕，钢管</td>
                <td>299</td>
                <td>10</td>
                <td>红色</td>
            </tr>
            <tr>
                <td colspan="8"></td>
            </tr>

        </tbody>
    </table>
    <div class="bottom-right">
        <h3>总价:<span class="total">0</span> 元</h3>
    </div>
</div>
<script type="text/javascript">
    $(function (){
        doGetOrder();
    });
    function doGetOrder(){
        let orderData = $("#mainContentId").data("orderData");
        let orderId = orderData.orderId;
        let url = `/shop/order/getorder`;
        let data = {"orderId":orderId};
        $.getJSON(url,data,function (result){
            if (result.status===200){
                doLoadOrder(result.data);
            }
        });

    }
    function doLoadOrder(order){
        $(".order-id").text(order.orderId);
        $(".order-buyer").text(order.username);
        let createdTime = doStringtoDate(new Date(order.created));
        $(".order-created").text(createdTime);
        $(".total").text(order.total);
        doLoadAddress(order.address);
        doLoadItems(order.item);
    }

    function doLoadAddress(address){
        $(".order-user").text(address.addrName);
        $(".order-phone").text(address.userPhone);
        $(".order-addr").text(address.address);
    }

    function doLoadItems(itemList){
        let tbody = $(".houtai-order-list");
        tbody.empty();
        for (let i = 0;i<itemList.length;i++){
            let tr = $(`<tr class="houtai-order-desc"></tr>`);
            tr.append(doCreateItems(i+1,itemList[i]));
            tbody.append(tr);
        }
    }
    function doCreateItems(i,item){
        return `<td>${i}</td>
                <td class="houtai-item-img">
                    <img src="${item.image}" />
                </td>
                <td>${item.title}</td>
                <td>${item.price}</td>
                <td>${item.num}</td>
                <td>${item.sizeName}</td>`;
    }

    function doStringtoDate(dateTime){
        let year = dateTime.getFullYear();
        let month = dateTime.getMonth()+1;
        let date = dateTime.getDate();
        let hours = dateTime.getHours();
        let min = dateTime.getMinutes();
        let seconds = dateTime.getSeconds();
        let dateTimes = year+"年"+month+"月"+date+"日 "+hours+"时"+min+"分"+seconds+"秒";
        return dateTimes;
    }
</script>
